from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-04 14:12:01.608979
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 04, Sep, 2021
Time: 14:12:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9805
Nobs: 404.000 HQIC: -46.5191
Log likelihood: 4398.87 FPE: 4.40373e-21
AIC: -46.8719 Det(Omega_mle): 3.53386e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.428862 0.094263 4.550 0.000
L1.Burgenland 0.104552 0.048613 2.151 0.031
L1.Kärnten -0.114787 0.024195 -4.744 0.000
L1.Niederösterreich 0.169914 0.105052 1.617 0.106
L1.Oberösterreich 0.124906 0.102428 1.219 0.223
L1.Salzburg 0.283004 0.050985 5.551 0.000
L1.Steiermark 0.022348 0.067554 0.331 0.741
L1.Tirol 0.109740 0.053433 2.054 0.040
L1.Vorarlberg -0.114163 0.048103 -2.373 0.018
L1.Wien -0.007042 0.093019 -0.076 0.940
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.009864 0.218663 0.045 0.964
L1.Burgenland -0.045505 0.112767 -0.404 0.687
L1.Kärnten 0.036994 0.056125 0.659 0.510
L1.Niederösterreich -0.202167 0.243691 -0.830 0.407
L1.Oberösterreich 0.493156 0.237604 2.076 0.038
L1.Salzburg 0.305596 0.118270 2.584 0.010
L1.Steiermark 0.109277 0.156706 0.697 0.486
L1.Tirol 0.316464 0.123949 2.553 0.011
L1.Vorarlberg -0.004531 0.111586 -0.041 0.968
L1.Wien -0.007437 0.215777 -0.034 0.973
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254995 0.047806 5.334 0.000
L1.Burgenland 0.088879 0.024654 3.605 0.000
L1.Kärnten -0.002964 0.012270 -0.242 0.809
L1.Niederösterreich 0.205073 0.053277 3.849 0.000
L1.Oberösterreich 0.168881 0.051947 3.251 0.001
L1.Salzburg 0.034919 0.025857 1.350 0.177
L1.Steiermark 0.019637 0.034260 0.573 0.567
L1.Tirol 0.063562 0.027099 2.346 0.019
L1.Vorarlberg 0.059978 0.024396 2.459 0.014
L1.Wien 0.108323 0.047175 2.296 0.022
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179476 0.046917 3.825 0.000
L1.Burgenland 0.047906 0.024196 1.980 0.048
L1.Kärnten -0.007015 0.012042 -0.583 0.560
L1.Niederösterreich 0.138370 0.052287 2.646 0.008
L1.Oberösterreich 0.318728 0.050981 6.252 0.000
L1.Salzburg 0.100133 0.025376 3.946 0.000
L1.Steiermark 0.131590 0.033623 3.914 0.000
L1.Tirol 0.076671 0.026595 2.883 0.004
L1.Vorarlberg 0.054926 0.023942 2.294 0.022
L1.Wien -0.041096 0.046298 -0.888 0.375
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208198 0.093383 2.230 0.026
L1.Burgenland -0.056875 0.048159 -1.181 0.238
L1.Kärnten -0.034793 0.023969 -1.452 0.147
L1.Niederösterreich 0.115841 0.104072 1.113 0.266
L1.Oberösterreich 0.167043 0.101472 1.646 0.100
L1.Salzburg 0.257043 0.050509 5.089 0.000
L1.Steiermark 0.082011 0.066924 1.225 0.220
L1.Tirol 0.122518 0.052934 2.315 0.021
L1.Vorarlberg 0.115711 0.047654 2.428 0.015
L1.Wien 0.027714 0.092151 0.301 0.764
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.027336 0.072529 0.377 0.706
L1.Burgenland 0.025053 0.037404 0.670 0.503
L1.Kärnten 0.051822 0.018616 2.784 0.005
L1.Niederösterreich 0.208569 0.080831 2.580 0.010
L1.Oberösterreich 0.338408 0.078812 4.294 0.000
L1.Salzburg 0.045073 0.039229 1.149 0.251
L1.Steiermark -0.003046 0.051979 -0.059 0.953
L1.Tirol 0.113740 0.041113 2.767 0.006
L1.Vorarlberg 0.063584 0.037012 1.718 0.086
L1.Wien 0.130352 0.071572 1.821 0.069
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183338 0.088392 2.074 0.038
L1.Burgenland 0.021132 0.045585 0.464 0.643
L1.Kärnten -0.058877 0.022688 -2.595 0.009
L1.Niederösterreich -0.119122 0.098510 -1.209 0.227
L1.Oberösterreich 0.194388 0.096049 2.024 0.043
L1.Salzburg 0.028124 0.047809 0.588 0.556
L1.Steiermark 0.299259 0.063347 4.724 0.000
L1.Tirol 0.490936 0.050105 9.798 0.000
L1.Vorarlberg 0.068630 0.045108 1.521 0.128
L1.Wien -0.104671 0.087226 -1.200 0.230
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160123 0.096371 1.662 0.097
L1.Burgenland -0.007728 0.049699 -0.155 0.876
L1.Kärnten 0.062482 0.024736 2.526 0.012
L1.Niederösterreich 0.199741 0.107401 1.860 0.063
L1.Oberösterreich -0.125493 0.104718 -1.198 0.231
L1.Salzburg 0.239563 0.052125 4.596 0.000
L1.Steiermark 0.153802 0.069065 2.227 0.026
L1.Tirol 0.051740 0.054627 0.947 0.344
L1.Vorarlberg 0.123906 0.049179 2.520 0.012
L1.Wien 0.144756 0.095099 1.522 0.128
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488350 0.052177 9.360 0.000
L1.Burgenland -0.010648 0.026908 -0.396 0.692
L1.Kärnten -0.010504 0.013392 -0.784 0.433
L1.Niederösterreich 0.206193 0.058149 3.546 0.000
L1.Oberösterreich 0.255838 0.056697 4.512 0.000
L1.Salzburg 0.022759 0.028221 0.806 0.420
L1.Steiermark -0.024015 0.037393 -0.642 0.521
L1.Tirol 0.070490 0.029576 2.383 0.017
L1.Vorarlberg 0.058366 0.026626 2.192 0.028
L1.Wien -0.053878 0.051488 -1.046 0.295
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019313 0.077591 0.134991 0.135074 0.040026 0.070019 0.000076 0.175111
Kärnten 0.019313 1.000000 -0.045631 0.125861 0.047311 0.069433 0.456554 -0.093436 0.092290
Niederösterreich 0.077591 -0.045631 1.000000 0.283813 0.085126 0.272314 0.022774 0.147030 0.254518
Oberösterreich 0.134991 0.125861 0.283813 1.000000 0.182823 0.286380 0.155282 0.106102 0.135290
Salzburg 0.135074 0.047311 0.085126 0.182823 1.000000 0.128578 0.058116 0.103483 0.051233
Steiermark 0.040026 0.069433 0.272314 0.286380 0.128578 1.000000 0.129467 0.088258 -0.026645
Tirol 0.070019 0.456554 0.022774 0.155282 0.058116 0.129467 1.000000 0.040405 0.116898
Vorarlberg 0.000076 -0.093436 0.147030 0.106102 0.103483 0.088258 0.040405 1.000000 -0.044892
Wien 0.175111 0.092290 0.254518 0.135290 0.051233 -0.026645 0.116898 -0.044892 1.000000